package com.example.studyplanning.mapper;

import com.example.studyplanning.entity.Like;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LikeMapper {
    //点赞，插入语句，输入心得ID和收藏用户ID
    @Insert("insert into liketable(userID,tipsID) VALUES (#{userID},#{tipsID})")
    Integer InsertLike(Like like);

    @Select("select tips.tipsTitle,tips.tipsContent,tips.tipsID,tips.likes,tips.tipsTime,user.userName,DATE_FORMAT(tips.tipsTime,'%Y-%m-%d') as date_time from tips INNER JOIN user on tips.userID=user.userID INNER JOIN liketable on liketable.tipsID=tips.tipsID where liketable.userID=#{userID} and liketable.tipsID=#{tipsID}")
    List<Like> FindLike(@Param("userID")Integer userID,@Param("tipsID")Integer tipsID);

    //取消点赞
    @Delete("delete from liketable where tipsID=#{tipsID} and userID=#{userID}")
    Integer DelLike(@Param("userID")Integer userID,@Param("tipsID")Integer tipsID);

}
